<template>
  <Dialog :title="title" :visible.sync="innerVisible">
    <el-row>
      <el-col :span="24">
        <BasicTable
          :url="url"
          onlyTable
          :columns="columns"
          ref="BasicTable"
        >
          <template slot="column">
            <el-table-column
              align="center"
              label="错误文件下载">
              <template slot-scope="scope">
                <a v-if="scope.row.errorFileId" class="blue-color"
                   :href="api + '/ms-mongodb/file/download?fileId=' + scope.row.errorFileId"
                >下载</a>
                <span v-else>无</span>
              </template>
            </el-table-column>
          </template>
        </BasicTable>
      </el-col>
    </el-row>
  </Dialog>
</template>

<script>
// status 1:正在导入2:导入成功 3导入失败
import {unixTimestampFilter} from '@/filters'
import {dataServiceConfig} from '@/config/index.js'
export default {
  name: 'ImportResult',
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    url: {
      type: String,
      default: '/ms-common-excelupload/excel/getRecentlyData'
    },
    title: {
      type: String,
      default: '导入结果'
    }
  },
  data() {
    return {
      innerVisible: false,
      api: dataServiceConfig.urlPrefix,
      tableData: [],
      columns: [
        {
          label: '文件名',
          data: 'fileOrgName'
        },
        {
          label: '导入时间',
          data: 'finishTime',
          render: (data, full) => {
            if (parseInt(full.status) === 1) {
              return '导入中'
            }
            return unixTimestampFilter(data)
          }
        },
        {
          label: '总条数',
          data: 'allCount'
        },
        {
          label: '导入成功',
          data: 'successCount',
          render: (data, full) => {
            if (parseInt(full.status) === 1) {
              return '导入中'
            }
            return data
          }
        },
        {
          label: '导入失败',
          data: 'fallCount',
          render: (data, full) => {
            if (parseInt(full.status) === 1) {
              return '导入中'
            }
            return full.allCount - full.successCount
          }
        }
      ]
    }
  },
  watch: {
    visible(val, oldVal) {
      if (val === oldVal) {
        return
      }
      if (val) {
        this.getResult()
      }
      this.innerVisible = val
    },
    innerVisible(val, oldVal) {
      if (val === oldVal) {
        return
      }
      this.$emit('update:visible', val)
    }
  },
  methods: {
    getResult() {
      const node = this.$refs.BasicTable
      if (node) {
        node.search({})
      }
    }
  }
}
</script>

<style scoped>

</style>
